/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.config.FileProperties;
import me.zhengjie.modules.system.domain.*;
import me.zhengjie.modules.system.domain.vo.BatchGroupTestDetailUserRespDTO;
import me.zhengjie.modules.system.service.BatchGroupTestService;
import me.zhengjie.modules.web.service.mybatisplus.IExamResultPlusService;
import me.zhengjie.modules.web.service.mybatisplus.IGroupTestDetailPlusService;
import me.zhengjie.modules.web.service.mybatisplus.IGroupTestPlusService;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class BatchGroupTestServiceImpl implements BatchGroupTestService {

    @Value("${qrcode.url}")
    String qrCodeUrl;

    @Value("${qrcode.authUrl}")
    String qrAuthUrl;

    @Value("${qrcode.child_url}")
    String childQrCodeUrl;

    @Autowired
    FileProperties properties;

    @Autowired
    private IGroupTestDetailPlusService groupTestDetailPlusService;

    @Autowired
    private IGroupTestPlusService groupTestPlusService;

    @Autowired
    private IExamResultPlusService examResultPlusService;

    @Override
    public Page<BatchGroupTestDetailRespDTO> batchDetail(BatchGroupTestDetailRequestDTO requestDTO) {

        // 详情类型，1：已测未完成，2：已测完，3：未测，4：已测总人员
        Integer detailType = requestDTO.getDetailType();
        GroupTest groupTest = groupTestPlusService.getById(requestDTO.getGroupId());

        switch (detailType){
            case 1:
                return batchDetailPage1(requestDTO, groupTest);
            case 2:
                return batchDetailPage2(requestDTO, groupTest);
            case 3:
                return batchDetailPage3(requestDTO, groupTest);
            case 4:
                return batchDetailPage4(requestDTO, groupTest);
            default:
                return null;
        }
    }

    private Page<BatchGroupTestDetailRespDTO> batchDetailPage1(BatchGroupTestDetailRequestDTO requestDTO, GroupTest groupTest) {
        Page<BatchGroupTestDetailRespDTO> respPage = new Page<>();
        Page<GroupTestDetail> page = Page.of(requestDTO.getPage(), requestDTO.getSize());
        LambdaQueryWrapper<GroupTestDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GroupTestDetail::getGroupId, requestDTO.getGroupId()).gt(GroupTestDetail::getTested,0).le(GroupTestDetail::getTested, groupTest.getLimitNum());
        if (StringUtils.isNotBlank(requestDTO.getSort()) && requestDTO.getSort().equalsIgnoreCase("DESC")){
            wrapper.orderByDesc(GroupTestDetail::getSerialNumber);
        }else {
            wrapper.orderByAsc(GroupTestDetail::getSerialNumber);
        }
        Page<GroupTestDetail> page1 = groupTestDetailPlusService.page(page, wrapper);
        if (CollectionUtils.isEmpty(page1.getRecords())){
            return respPage;
        }
        List<BatchGroupTestDetailRespDTO> detailRespDTOS = page1.getRecords().stream().map(detail -> {
            BatchGroupTestDetailRespDTO respDTO = new BatchGroupTestDetailRespDTO();
            respDTO.setGroupId(detail.getGroupId());
            respDTO.setGroupIndex(detail.getSerialNumber());
            respDTO.setDetailCode(detail.getSerialCode());
            respDTO.setTestedNum(detail.getTested());
            respDTO.setSurplusNum(groupTest.getLimitNum() - detail.getTested());
            return respDTO;
        }).collect(Collectors.toList());
        respPage.setRecords(detailRespDTOS);
        respPage.setTotal(page1.getTotal());
        respPage.setPages(page1.getPages());
        return respPage;
    }

    private Page<BatchGroupTestDetailRespDTO> batchDetailPage2(BatchGroupTestDetailRequestDTO requestDTO, GroupTest groupTest) {
        Page<BatchGroupTestDetailRespDTO> respPage = new Page<>();
        Page<GroupTestDetail> page = Page.of(requestDTO.getPage(), requestDTO.getSize());
        LambdaQueryWrapper<GroupTestDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GroupTestDetail::getGroupId, requestDTO.getGroupId()).eq(GroupTestDetail::getTested, groupTest.getLimitNum());
        if (StringUtils.isNotBlank(requestDTO.getSort()) && requestDTO.getSort().equalsIgnoreCase("DESC")){
            wrapper.orderByDesc(GroupTestDetail::getSerialNumber);
        }else {
            wrapper.orderByAsc(GroupTestDetail::getSerialNumber);
        }
        Page<GroupTestDetail> page1 = groupTestDetailPlusService.page(page, wrapper);
        if (CollectionUtils.isEmpty(page1.getRecords())){
            return respPage;
        }
        List<BatchGroupTestDetailRespDTO> detailRespDTOS = page1.getRecords().stream().map(detail -> {
            BatchGroupTestDetailRespDTO respDTO = new BatchGroupTestDetailRespDTO();
            respDTO.setGroupId(detail.getGroupId());
            respDTO.setGroupIndex(detail.getSerialNumber());
            respDTO.setDetailCode(detail.getSerialCode());
            respDTO.setTestedNum(detail.getTested());
            respDTO.setSurplusNum(groupTest.getLimitNum() - detail.getTested());
            return respDTO;
        }).collect(Collectors.toList());
        respPage.setRecords(detailRespDTOS);
        respPage.setTotal(page1.getTotal());
        respPage.setPages(page1.getPages());
        return respPage;
    }

    private Page<BatchGroupTestDetailRespDTO> batchDetailPage3(BatchGroupTestDetailRequestDTO requestDTO, GroupTest groupTest) {
        Page<BatchGroupTestDetailRespDTO> respPage = new Page<>();
        Page<GroupTestDetail> page = Page.of(requestDTO.getPage(), requestDTO.getSize());
        LambdaQueryWrapper<GroupTestDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GroupTestDetail::getGroupId, requestDTO.getGroupId()).eq(GroupTestDetail::getTested, 0);
        if (StringUtils.isNotBlank(requestDTO.getSort()) && requestDTO.getSort().equalsIgnoreCase("DESC")){
            wrapper.orderByDesc(GroupTestDetail::getSerialNumber);
        }else {
            wrapper.orderByAsc(GroupTestDetail::getSerialNumber);
        }
        Page<GroupTestDetail> page1 = groupTestDetailPlusService.page(page, wrapper);
        if (CollectionUtils.isEmpty(page1.getRecords())){
            return respPage;
        }
        List<BatchGroupTestDetailRespDTO> detailRespDTOS = page1.getRecords().stream().map(detail -> {
            BatchGroupTestDetailRespDTO respDTO = new BatchGroupTestDetailRespDTO();
            respDTO.setGroupId(detail.getGroupId());
            respDTO.setGroupIndex(detail.getSerialNumber());
            respDTO.setDetailCode(detail.getSerialCode());
            respDTO.setTestedNum(detail.getTested());
            respDTO.setSurplusNum(groupTest.getLimitNum() - detail.getTested());
            return respDTO;
        }).collect(Collectors.toList());
        respPage.setRecords(detailRespDTOS);
        respPage.setTotal(page1.getTotal());
        respPage.setPages(page1.getPages());
        return respPage;
    }
    private Page<BatchGroupTestDetailRespDTO> batchDetailPage4(BatchGroupTestDetailRequestDTO requestDTO, GroupTest groupTest) {
        Page<BatchGroupTestDetailRespDTO> respPage = new Page<>();
        Page<GroupTestDetail> page = Page.of(requestDTO.getPage(), requestDTO.getSize());
        LambdaQueryWrapper<GroupTestDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GroupTestDetail::getGroupId, requestDTO.getGroupId()).gt(GroupTestDetail::getTested, 0);
        if (StringUtils.isNotBlank(requestDTO.getSort()) && requestDTO.getSort().equalsIgnoreCase("DESC")){
            wrapper.orderByDesc(GroupTestDetail::getSerialNumber);
        }else {
            wrapper.orderByAsc(GroupTestDetail::getSerialNumber);
        }
        Page<GroupTestDetail> page1 = groupTestDetailPlusService.page(page, wrapper);
        if (CollectionUtils.isEmpty(page1.getRecords())){
            return respPage;
        }
        List<BatchGroupTestDetailRespDTO> detailRespDTOS = page1.getRecords().stream().map(detail -> {
            BatchGroupTestDetailRespDTO respDTO = new BatchGroupTestDetailRespDTO();
            respDTO.setGroupId(detail.getGroupId());
            respDTO.setGroupIndex(detail.getSerialNumber());
            respDTO.setDetailCode(detail.getSerialCode());
            respDTO.setTestedNum(detail.getTested());
            respDTO.setSurplusNum(groupTest.getLimitNum() - detail.getTested());
            return respDTO;
        }).collect(Collectors.toList());
        respPage.setRecords(detailRespDTOS);
        respPage.setTotal(page1.getTotal());
        respPage.setPages(page1.getPages());
        return respPage;
    }
    @Override
    public Page<BatchGroupTestDetailUserRespDTO> batchUser(BatchGroupTestDetailUserRequestDTO requestDTO) {
        //测评人员类型，1：已测未完成，2：已测完，3：已测总人员
        Integer userType = requestDTO.getUserType();
        if (StringUtils.isBlank(requestDTO.getGroupCode())){
            throw new RuntimeException("分组编码不能为空");
        }
        switch (userType){
            case 1:
                return userDetailPage1(requestDTO);
            case 2:
                return userDetailPage2(requestDTO);
            case 4:
                return userDetailPage3(requestDTO);
            default:
                return null;
        }
    }

    @Override
    public Page<BatchGroupTestDetailUserRespDTO> batchAllUser(BatchGroupTestDetailUserRequestDTO requestDTO) {
        Page<BatchGroupTestDetailUserRespDTO> page = Page.of(requestDTO.getPage(), requestDTO.getSize());
        if (Objects.isNull(requestDTO.getGroupId())){
            throw new RuntimeException("团测ID不能为空");
        }
        Page<ExamResult> pageResult = Page.of(requestDTO.getPage(), requestDTO.getSize());
        LambdaQueryWrapper<ExamResult> examResultWrapper = new LambdaQueryWrapper<>();
        examResultWrapper.eq(ExamResult::getGroupId,requestDTO.getGroupId());

        if(Objects.nonNull(requestDTO.getGroupIndex())){
            LambdaQueryWrapper<GroupTestDetail> detailWrapper = new LambdaQueryWrapper<>();
            detailWrapper.eq(GroupTestDetail::getGroupId, requestDTO.getGroupId());
            detailWrapper.eq(GroupTestDetail::getSerialNumber, requestDTO.getGroupIndex());
            GroupTestDetail one = groupTestDetailPlusService.getOne(detailWrapper);
            if (Objects.isNull( one)){
                return page;
            }
            examResultWrapper.eq(ExamResult::getGroupCode, one.getSerialCode());
        }
        if (StringUtils.isNotBlank(requestDTO.getNickName())){
            examResultWrapper.eq(ExamResult::getWxName, requestDTO.getNickName());
        }
        if (StringUtils.isNotBlank(requestDTO.getMobile())){
            examResultWrapper.eq(ExamResult::getMobile, requestDTO.getMobile());
        }
        if (StringUtils.isNotBlank(requestDTO.getAtmrResultType())){
            examResultWrapper.like(ExamResult::getAtmrResultType, requestDTO.getAtmrResultType());
        }
        if (StringUtils.isNotBlank(requestDTO.getOpenId())){
            examResultWrapper.eq(ExamResult::getWxId, requestDTO.getOpenId());
        }
        if (StringUtils.isNotBlank(requestDTO.getUserName())){
            examResultWrapper.eq(ExamResult::getWxRealName, requestDTO.getUserName());
        }
        if (StringUtils.isNotBlank(requestDTO.getSort()) && requestDTO.getSort().equalsIgnoreCase("DESC")){
            examResultWrapper.orderByDesc(ExamResult::getExamTime);
        }else {
            examResultWrapper.orderByAsc(ExamResult::getExamTime);
        }
        Page<ExamResult> page1 = examResultPlusService.page(pageResult, examResultWrapper);
        List<BatchGroupTestDetailUserRespDTO> records = new ArrayList<>();
        page1.getRecords().forEach(examResult -> {
            BatchGroupTestDetailUserRespDTO respDTO = new BatchGroupTestDetailUserRespDTO();

            LambdaQueryWrapper<GroupTestDetail> detailWrapper = new LambdaQueryWrapper<>();
            detailWrapper.eq(GroupTestDetail::getSerialCode,examResult.getGroupCode());
            GroupTestDetail one = groupTestDetailPlusService.getOne(detailWrapper);
            if (Objects.nonNull(one)){
                respDTO.setGroupIndex(one.getSerialNumber());
            }else {
                respDTO.setGroupIndex(0);
            }
            respDTO.setUserName(examResult.getWxRealName());
            respDTO.setMobile(examResult.getMobile());
            respDTO.setOpenId(examResult.getWxId());
            respDTO.setNickName(examResult.getWxName());
            respDTO.setAtmrResultType(examResult.getAtmrResultType());
            respDTO.setAtmrId(examResult.getAtmrId());
            respDTO.setReportUrl(examResult.getReportUrl());
            respDTO.setExamTime(examResult.getExamTime());
            records.add(respDTO);
        });
        page.setRecords(records);
        page.setTotal(page1.getTotal());
        page.setPages(page1.getPages());
        return page;
    }

    @Override
    public void download(Long groupId, HttpServletResponse response) throws IOException {
        GroupTest groupTest = groupTestPlusService.getById(groupId);
        if (Objects.isNull(groupTest)){
            throw new RuntimeException("未找到该分组");
        }
        LambdaQueryWrapper<GroupTestDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GroupTestDetail::getGroupId, groupId);
        List<GroupTestDetail> detailList = groupTestDetailPlusService.list(queryWrapper);
        if (CollectionUtils.isEmpty(detailList)){
            return;
        }
        List<Map<String, Object>> list = new ArrayList<>();
        for (GroupTestDetail detail : detailList) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("标题", groupTest.getTitle());
            map.put("二维码编号", detail.getSerialNumber());
            map.put("测评地址", detail.getQrCodeText());
            list.add(map);
        }
        FileUtil.downloadExcel(list,groupTest.getTitle(), response);
    }

    private Page<BatchGroupTestDetailUserRespDTO> userDetailPage1(BatchGroupTestDetailUserRequestDTO requestDTO) {
        Page<BatchGroupTestDetailUserRespDTO> page = Page.of(requestDTO.getPage(), requestDTO.getSize());

        Page<ExamResult> pageResult = Page.of(requestDTO.getPage(), requestDTO.getSize());
        LambdaQueryWrapper<ExamResult> examResultWrapper = new LambdaQueryWrapper<>();
        examResultWrapper.eq(ExamResult::getGroupCode,requestDTO.getGroupCode());
        if (StringUtils.isNotBlank(requestDTO.getNickName())){
            examResultWrapper.eq(ExamResult::getWxName, requestDTO.getNickName());
        }
        if (StringUtils.isNotBlank(requestDTO.getMobile())){
            examResultWrapper.eq(ExamResult::getMobile, requestDTO.getMobile());
        }
        if (StringUtils.isNotBlank(requestDTO.getAtmrResultType())){
            examResultWrapper.like(ExamResult::getAtmrResultType, requestDTO.getAtmrResultType());
        }
        if (StringUtils.isNotBlank(requestDTO.getOpenId())){
            examResultWrapper.eq(ExamResult::getWxId, requestDTO.getOpenId());
        }
        if (StringUtils.isNotBlank(requestDTO.getUserName())){
            examResultWrapper.eq(ExamResult::getWxRealName, requestDTO.getUserName());
        }
        if (StringUtils.isNotBlank(requestDTO.getSort()) && requestDTO.getSort().equalsIgnoreCase("DESC")){
            examResultWrapper.orderByDesc(ExamResult::getExamTime);
        }else {
            examResultWrapper.orderByAsc(ExamResult::getExamTime);
        }
        Page<ExamResult> page1 = examResultPlusService.page(pageResult, examResultWrapper);
        List<BatchGroupTestDetailUserRespDTO> records = new ArrayList<>();
        page1.getRecords().forEach(examResult -> {
            BatchGroupTestDetailUserRespDTO respDTO = new BatchGroupTestDetailUserRespDTO();

            LambdaQueryWrapper<GroupTestDetail> detailWrapper = new LambdaQueryWrapper<>();
            detailWrapper.eq(GroupTestDetail::getSerialCode,examResult.getGroupCode());
            GroupTestDetail one = groupTestDetailPlusService.getOne(detailWrapper);
            if (Objects.nonNull(one)){
                respDTO.setGroupIndex(one.getSerialNumber());
            }else {
                respDTO.setGroupIndex(0);
            }
            respDTO.setUserName(examResult.getWxRealName());
            respDTO.setMobile(examResult.getMobile());
            respDTO.setOpenId(examResult.getWxId());
            respDTO.setNickName(examResult.getWxName());
            respDTO.setAtmrResultType(examResult.getAtmrResultType());
            respDTO.setAtmrId(examResult.getAtmrId());
            respDTO.setReportUrl(examResult.getReportUrl());
            respDTO.setExamTime(examResult.getExamTime());
            records.add(respDTO);
        });
        page.setRecords(records);
        page.setTotal(page1.getTotal());
        page.setPages(page1.getPages());
        return page;
    }

    private Page<BatchGroupTestDetailUserRespDTO> userDetailPage2(BatchGroupTestDetailUserRequestDTO requestDTO) {
        Page<BatchGroupTestDetailUserRespDTO> page = Page.of(requestDTO.getPage(), requestDTO.getSize());

        Page<ExamResult> pageResult = Page.of(requestDTO.getPage(), requestDTO.getSize());
        LambdaQueryWrapper<ExamResult> examResultWrapper = new LambdaQueryWrapper<>();
        examResultWrapper.eq(ExamResult::getGroupCode,requestDTO.getGroupCode());
        if (StringUtils.isNotBlank(requestDTO.getNickName())){
            examResultWrapper.eq(ExamResult::getWxName, requestDTO.getNickName());
        }
        if (StringUtils.isNotBlank(requestDTO.getMobile())){
            examResultWrapper.eq(ExamResult::getMobile, requestDTO.getMobile());
        }
        if (StringUtils.isNotBlank(requestDTO.getAtmrResultType())){
            examResultWrapper.like(ExamResult::getAtmrResultType, requestDTO.getAtmrResultType());
        }
        if (StringUtils.isNotBlank(requestDTO.getOpenId())){
            examResultWrapper.eq(ExamResult::getWxId, requestDTO.getOpenId());
        }
        if (StringUtils.isNotBlank(requestDTO.getUserName())){
            examResultWrapper.eq(ExamResult::getWxRealName, requestDTO.getUserName());
        }
        if (StringUtils.isNotBlank(requestDTO.getSort()) && requestDTO.getSort().equalsIgnoreCase("DESC")){
            examResultWrapper.orderByDesc(ExamResult::getExamTime);
        }else {
            examResultWrapper.orderByAsc(ExamResult::getExamTime);
        }
        Page<ExamResult> page1 = examResultPlusService.page(pageResult, examResultWrapper);
        List<BatchGroupTestDetailUserRespDTO> records = new ArrayList<>();
        page1.getRecords().forEach(examResult -> {
            BatchGroupTestDetailUserRespDTO respDTO = new BatchGroupTestDetailUserRespDTO();

            LambdaQueryWrapper<GroupTestDetail> detailWrapper = new LambdaQueryWrapper<>();
            detailWrapper.eq(GroupTestDetail::getSerialCode,examResult.getGroupCode());
            GroupTestDetail one = groupTestDetailPlusService.getOne(detailWrapper);
            if (Objects.nonNull(one)){
                respDTO.setGroupIndex(one.getSerialNumber());
            }else {
                respDTO.setGroupIndex(0);
            }
            respDTO.setUserName(examResult.getWxRealName());
            respDTO.setMobile(examResult.getMobile());
            respDTO.setOpenId(examResult.getWxId());
            respDTO.setNickName(examResult.getWxName());
            respDTO.setAtmrResultType(examResult.getAtmrResultType());
            respDTO.setAtmrId(examResult.getAtmrId());
            respDTO.setReportUrl(examResult.getReportUrl());
            respDTO.setExamTime(examResult.getExamTime());
            records.add(respDTO);
        });
        page.setRecords(records);
        page.setTotal(page1.getTotal());
        page.setPages(page1.getPages());
        return page;
    }

    private Page<BatchGroupTestDetailUserRespDTO> userDetailPage3(BatchGroupTestDetailUserRequestDTO requestDTO) {
        Page<BatchGroupTestDetailUserRespDTO> page = Page.of(requestDTO.getPage(), requestDTO.getSize());

        Page<ExamResult> pageResult = Page.of(requestDTO.getPage(), requestDTO.getSize());
        LambdaQueryWrapper<ExamResult> examResultWrapper = new LambdaQueryWrapper<>();
        examResultWrapper.eq(ExamResult::getGroupCode,requestDTO.getGroupCode());
        if (StringUtils.isNotBlank(requestDTO.getNickName())){
            examResultWrapper.eq(ExamResult::getWxName, requestDTO.getNickName());
        }
        if (StringUtils.isNotBlank(requestDTO.getMobile())){
            examResultWrapper.eq(ExamResult::getMobile, requestDTO.getMobile());
        }
        if (StringUtils.isNotBlank(requestDTO.getAtmrResultType())){
            examResultWrapper.like(ExamResult::getAtmrResultType, requestDTO.getAtmrResultType());
        }
        if (StringUtils.isNotBlank(requestDTO.getOpenId())){
            examResultWrapper.eq(ExamResult::getWxId, requestDTO.getOpenId());
        }
        if (StringUtils.isNotBlank(requestDTO.getUserName())){
            examResultWrapper.eq(ExamResult::getWxRealName, requestDTO.getUserName());
        }
        if (StringUtils.isNotBlank(requestDTO.getSort()) && requestDTO.getSort().equalsIgnoreCase("DESC")){
            examResultWrapper.orderByDesc(ExamResult::getExamTime);
        }else {
            examResultWrapper.orderByAsc(ExamResult::getExamTime);
        }
        Page<ExamResult> page1 = examResultPlusService.page(pageResult, examResultWrapper);
        List<BatchGroupTestDetailUserRespDTO> records = new ArrayList<>();
        page1.getRecords().forEach(examResult -> {
            BatchGroupTestDetailUserRespDTO respDTO = new BatchGroupTestDetailUserRespDTO();

            LambdaQueryWrapper<GroupTestDetail> detailWrapper = new LambdaQueryWrapper<>();
            detailWrapper.eq(GroupTestDetail::getSerialCode,examResult.getGroupCode());
            GroupTestDetail one = groupTestDetailPlusService.getOne(detailWrapper);
            if (Objects.nonNull(one)){
                respDTO.setGroupIndex(one.getSerialNumber());
            }else {
                respDTO.setGroupIndex(0);
            }
            respDTO.setUserName(examResult.getWxRealName());
            respDTO.setMobile(examResult.getMobile());
            respDTO.setOpenId(examResult.getWxId());
            respDTO.setNickName(examResult.getWxName());
            respDTO.setAtmrResultType(examResult.getAtmrResultType());
            respDTO.setAtmrId(examResult.getAtmrId());
            respDTO.setReportUrl(examResult.getReportUrl());
            respDTO.setExamTime(examResult.getExamTime());
            records.add(respDTO);
        });
        page.setRecords(records);
        page.setTotal(page1.getTotal());
        page.setPages(page1.getPages());
        return page;
    }
}